#Replication material for "Attention Deficit Disorder"
#iga and jvk
#2-9-2022

#Manual Content Analysis Replication Materials

#required packages
library(tidyverse)
library(ggthemes)
library(psych)


#readin

dat <- read.csv("manual_content_analysis.csv")


###Intercoder reliability of two measures

#mention
dat %>%
  select(mention,mention_ia) %>%
  cohen.kappa(w=NULL)

#responsibility
dat %>%
  select(incResponsible,incResponsible_ia) %>%
  cohen.kappa(w=NULL)


#Graphics

dat %>%
  group_by(maddow,trumpEra,incResponsible_ia) %>%
  summarize(sum = n(),
            mention = mean(mention)) %>%
  mutate(respProp = sum*mention) %>%
  ggplot() + 
  geom_bar(aes(x=trumpEra,y=100*respProp/50,group=incResponsible_ia,fill=incResponsible_ia),stat='identity')+
  facet_wrap(~maddow,ncol=2) +
  theme_few() +
  xlab("Transcript Source") +
  ylab("% of Transcripts") +
  theme(legend.title = element_blank()) +
  scale_fill_grey()


dat2 <- dat %>%
  group_by(maddow,trumpEra,incResponsible_ia) %>%
  summarize(sum = n(),
            mention = mean(mention)) %>%
  mutate(respProp = sum*mention) %>%
  filter(incResponsible_ia=="Explicit Incumbent Responsibility Attribution") %>%
  mutate(value = respProp/50)


dat2$se = sqrt(50*dat2$value*(1-dat2$value))
dat2$lo = 2*dat2$respProp - 1.96*dat2$se
dat2$hi = 2*dat2$respProp + 1.96*dat2$se


a <- ggplot(data=dat2) + 
  geom_bar(aes(x=trumpEra,y=2*respProp),stat='identity')+
  geom_errorbar(aes(x=trumpEra,ymin=lo,ymax=hi),width=0.1)+
  facet_wrap(~maddow,ncol=2) +
  theme_few() +
  xlab("Transcript Source") +
  ylab("% of Transcripts") +
  scale_fill_grey()

a

